import {createStore} from 'vuex'
import storeA from './modules/moduleA'
import storeB from './modules/moduleB'
import MqttUtils, {destroyMqttClient, Topic as MqttTopic} from "@/utils/MqttUtils";
import WsUtils from "@/net/ws/WsUtils";
import protoRoot from "/src/net/proto/proto";
import FRangeBean from "@/bean/FRangeBean";

let Command = protoRoot.lookup("Command")
let FrequencyRange = protoRoot.lookup("FrequencyRange")

export default createStore({
    state: {
        countNum: 2,
    },
    mutations: {
        increment(state) {
            state.countNum++
        },

        initMqtt() {
            MqttUtils.Subscribe(MqttTopic.DevStatus)
        },

        destroyMqtt() {
            destroyMqttClient()
        },

        handleMqttMsg() {

        },

        initWs() {
            WsUtils.getWsInstance().createWebSocket()
        },

        sendWsMsg() {
            //用于测试,后面传入参数既可
            let fRange = new FRangeBean(40, 15)
            let encodeValue = FrequencyRange.encode(fRange).finish()
            console.log('+++++++++++++++', encodeValue);
            WsUtils.sendEvent('0:0:0:1', Command.values.SetFRange, encodeValue)
        }
    },
    actions: {},
    modules: {storeA, storeB}
})